import React from 'react';
import {Form, Row, Col, Button,Input} from 'antd';
import {injectIntl} from 'react-intl';
import SCModal from '../../components/pickCity/SCModal';
import axios from 'axios'

const FormItem = Form.Item;
const createForm = Form.create;
class modifyGroup extends React.Component {
    constructor(props) {
        super(props);
        this.state={
            stationName:''
        }
    }

    componentWillReceiveProps(nextProps) {
        if(nextProps.visible){
            this.setState({
                stationName:nextProps.currentRowInfo.stationName
            })
        }
    }

    handleSubmit = (e) => {
        e.preventDefault();
        this.props.form.validateFieldsAndScroll((errors, values) => {
            if (!!errors) {
                console.log('Errors in form!!!');
                return;
            }
            console.log('Submit!!!',values,this.props.currentRowInfo);
            values.stationId=this.props.currentRowInfo.stationId;
            axios.post('/api/evcs/stubGroup/update',{...values}).then(res=>{
                this.props.onCancel();
                this.props.freshGrid();
            })
        });
    }

    render(){
        const { getFieldDecorator } = this.props.form;
        const common = this.props.intl.messages.common;
        return(
            <SCModal visible={this.props.visible} title={common.modify}  onCancel={this.props.onCancel}>
                <form  form={this.props.form} style={{width:'60%'}}>
                    <Row>
                        <FormItem
                            label={common.powerStationName}
                        >
                            {getFieldDecorator('name',{
                                rules:[
                                    {
                                        required: true,
                                        message: common.pleaseFillInStubName
                                    },
                                ],
                                initialValue:this.state.stationName
                            })(
                                <Input  />
                            )}
                        </FormItem>
                        <FormItem wrapperCol={{span: 16, offset: 0}} style={{marginTop: 24}}>
                            <Button type="primary" htmlType="submit" onClick={this.handleSubmit}>{common.sure}</Button>
                        </FormItem>
                    </Row>
                </form>
            </SCModal>
        )
    }

}

modifyGroup = createForm()(modifyGroup);
export default injectIntl(modifyGroup)